<template lang="pug">
  .clearfix
    .form-shebao-title.font-16.font-weight 员工基本信息

    .clearfix.bg-white.pt-20.pr-20.pb-20.mb-20(:class="isOnlyView ? 'has-disabled' : ''")
      Form.ivu-row.ivu-form-basic.has-rules-item2(ref="formBasicInfo" :model="formBasicInfo" :rules="setRules" :label-width="130")
        FormItem.form-item.ivu-col.ivu-col-span-6(v-for="(item, index) of formBasicInfoItem" :label="item.label + '：'" :key="index" :class="item.style" :prop="item.prop")
          template(v-if="item.type === 'input'")
            //- 带有绑定事件的input
            Input(v-if="item.fn" v-model="formBasicInfo[item.model]" :placeholder="isOnlyView ? '未填写' : item.placeholder" :disabled="item.isDisabled || isOnlyView" @on-blur="listenCall(item.fn, index, item.model, formBasicInfo[item.model])")

            //- 工资卡名称input
            Input(v-else-if="item.model === 'accountName'" v-model="formBasicInfo.name" :placeholder="isOnlyView ? '未填写' : item.placeholder" :disabled="item.isDisabled || isOnlyView" @on-blur="listenCall(item.fn, index)")

            //- 证件类型input
            Input(v-else-if="item.model === 'idCardNo'" v-model="formBasicInfo[item.model]" :placeholder="isOnlyView ? '未填写' : item.placeholder" :disabled="item.isDisabled || isOnlyView")
            Input(v-else-if="item.model === 'otherIdCardNo'" v-model="formBasicInfo[item.model]" :placeholder="isOnlyView ? '未填写' : item.placeholder" :disabled="item.isDisabled || isOnlyView")

            //-其他默认input
            Input(v-else v-model="formBasicInfo[item.model]" :placeholder="isOnlyView ? '未填写' : item.placeholder" :disabled="item.isDisabled || isOnlyView")

          template(v-if="item.type === 'select'")
            //-城市下拉选择select
            //- Select(v-if="item.prop === 'city'" v-model="formBasicInfo[item.model]" :placeholder="isOnlyView ? '未填写' : item.placeholder" clearable :disabled="item.isDisabled || isOnlyView")
            //-   Option(v-for="(c_item, c_index) of arrListDown[item.options]" :key="c_index" :value="c_item.id") {{c_item.name}}

            //-带有绑定事件的select
            Select(v-if="item.fn" v-model="formBasicInfo[item.model]" :placeholder="isOnlyView ? '未填写' : item.placeholder" :disabled="item.isDisabled || isOnlyView" @on-change="listenCall(item.fn, $event)")
              Option(v-for="(c_item, c_index) of arrListDown[item.options]" :key="c_index" :value="c_item.value") {{c_item.label}}

            //-其他默认select
            Select(v-else v-model="formBasicInfo[item.model]" :placeholder="isOnlyView ? '未填写' : item.placeholder" clearable :disabled="item.isDisabled || isOnlyView")
              Option(v-for="(c_item, c_index) of arrListDown[item.options]" :key="c_index" :value="c_item.value" :disabled="c_item.isDisabled") {{c_item.label}}

          template(v-if="item.type === 'datePicker'")
            DatePicker.w-100(:value="formBasicInfo[item.model]" :placeholder="isOnlyView ? '未填写' : item.placeholder" type="date" :disabled="item.isDisabled || isOnlyView" @on-change="handleChangeDatePicker(item.model, $event)")

          template(v-if="item.type === 'cascader'")
            .areaTree
              Cascader(v-model="formBasicInfo[item.model]" :data="areaTree" :load-data="loadDataCity" clearable :disabled="item.isDisabled || isOnlyView" @on-change="areaTreeChange(item.model, $event)")

    //- .clearfix.bg-white.pt-20.pr-20.pb-20.mb-20(v-else)
    //-   Row.line-h-30
    //-     Col.mb-10(v-for="(item, index) of formBasicInfoItem" :key="index" :class="item.style")
    //-       span.w120.display-inline-block.text-right.pr-12 {{item.label}}
    //-       span.text-gray-9 未填写

    //- 添加离职信息 暂时隐藏
    //- .clearfix.bg-white.border-b-dashed.pall-20
    //-   Table.hasTitle-table(border :columns="thead" :data="tableData" :stripe="true")
    //-     .clearfix.pr-24.pl-12.overflow-hidden(slot="header")
    //-       .pull-right
    //-         Button(type="info") 添加离职信息

    //- 仅展示详情时的按钮
    .clearfix.text-center.mt-20.mb-20(v-if="isOnlyView")
      Button.mr-10(type="info" @click="handleModify") 修改
      Button.mr-10(type="info" @click="handlepageDown") 查看下一页
      Button(v-if="!isFromRoster" type="info" ghost @click="goEmployeeBookList()") 返回花名册
      Button(v-if="isFromRoster" type="info" ghost @click="goRoster()") 返回员工管理

    //- 新建或修改时的按钮
    .clearfix.text-center.mt-20.mb-20(v-if="!isOnlyView")
      Button.mr-10(type="info" @click="handleSubmit('formBasicInfo')") 保存
      //- 当employeeId不存在时，页面为新建状态，必须先保存当前步骤才能继续下一步
      Button(type="info" @click="handlepageDown" :disabled="!isNext") 下一步

    .pt-18(v-if="formBasicInfo.beHiring == 'false' && tableData.length === 0 && !isToBeStaff")
      Button(type="info" @click="handleShowCreateDepartureInfoModal('')") 添加离职信息
    CreateDepartureInfoModal(ref="CreateDepartureInfoModal" @postResignInfoOk="getResignInfoList")

    .clearfix.pt-20.pr-20.pb-20.mb-20(v-if="tableData.length > 0")
      //- .form-shebao-title.font-16.font-weight 员工离职信息
      Table(border :columns="thead" :data="tableData" :stripe="true" ref="demoTable")
        .clearfix.pr-24.pl-24.font-16(slot="header") 员工离职信息
        //- template(slot-scope="{ row, index }" slot="action")
        //-   Button.mr-10(type="text" size="small" @click="handleShowCreateDepartureInfoModal(row.id)") 编辑
</template>

<script>
import dataApi from '@/api/data.js'
import { EmployeesApi } from '@/api/Employees.api.js'
import { SysBasedataApi } from '@/api/SysBasedata.api.js'
import { OrganizationBankApi } from '@/api/OrganizationBank.api.js'
import { lizhiThead } from './../EBtableHead.js'
import _cloneDeep from 'clone-deep'
import { Common } from '@/utils/common.js'
import CreateDepartureInfoModal from './createDepartureInfoModal.vue' // 添加离职信息
// import { ProvinceList, AreaTree } from '@/utils/publicJson.js'
import { EBbase } from '../EBbase.js'
import { EmployeeQuickEntryApi } from '@/api/EmployeeQuickEntry.api.js'


export default {
  name: '',

  components: {
    CreateDepartureInfoModal
  },

  props: {
    // companyId: {
    //   type: String,
    //   default: ''
    // },
    // companyName: {
    //   type: String,
    //   default: ''
    // },
    // employeeId: {
    //   type: String,
    //   default: ''
    // },
    // isOnlyView: {
    //   type: Boolean,
    //   default: false
    // }
    // areaTree: {
    //   type: Array,
    //   default: () => {
    //     return []
    //   }
    // }
  },

  computed: {
    setRules () {
      if (this.formBasicInfo.idType == 0) {
        console.log('选择的是身份证')
        this.rules.otherIdCardNo = [{ required: true, message: '请输入证件号码' }]
        this.rules.idCardNo = [{ required: true, type: 'string', validator: Common.validateIdCardNo }]
      } else {
        console.log('选择的是其他证件')
        this.rules.otherIdCardNo = [{ required: true, message: '请输入证件号码' }]
        this.rules.idCardNo = []
      }

      // if (this.currentCustomerManage.typeValue === 1) {
      //   this.formBasicInfoItem = this.formBasicInfoItem.slice(0, this.formBasicInfoItem.length - 3)
      //   this.rules.accountName = []
      //   this.rules.bankName = []
      //   this.rules.accountNo = []
      // }
      // console.log('其他证件：this.rules.otherIdCardNo 🚩 ', this.rules.otherIdCardNo)
      // console.log('身份证：this.rules.idCardNo 🚩 ', this.rules.idCardNo)
      return this.rules
    },

    actionArr () {
      let arr = this.$store.state.user.actionAccess.map(item => {
        return item.code
      })
      return arr
    },

    // 编辑
    hasEdit () {
      return this.actionArr.indexOf('Edit') > -1
    }
  },

  watch: {
    // setRules (val) {
    //   if (this.currentCustomerManage.typeValue === 1) {
    //     console.log('☆ 银行信息 非必填')
    //   } else {
    //     console.log('❤ 银行信息 必填')
    //   }
    // }
  },

  data () {
    return {
      isOnlyView: true,
      thead: _cloneDeep(lizhiThead),
      tableData: [],
      // 员工基本信息form
      formBasicInfo: {
        id: '', // 员工ID
        companyId: '', // 公司ID
        companyName: '', // 公司名称
        insuranceId: '', // 保险ID
        name: '',
        eName: '',
        idType: '0',
        idCardNo: '',
        otherIdCardNo: '',
        birthDay: '',
        sex: '',
        age: '',
        race: '',
        birthplace: '',
        idCardStartTime: '',
        idCardEndTime: '',
        idCardAddress: '',
        residentAddress: '',
        phone: '',
        email: '',
        emergencyContact: '',
        emergencyContactPhone: '',
        maritalStatus: '',
        hasChildren: '',
        professionalTitle: '',
        degree: '',
        schoolName: '',
        graduationDate: '',
        discipline: '',
        onBoardingDate: '',
        department: '',
        duty: '',
        employeeNo: '',
        employeeType: '',
        employeeTypeName: '',
        beHiring: 'true',
        beHiringName: '在职',
        city: [],
        cityStr: '',
        accountName: '',
        bankName: '',
        accountNo: '',
        salaryCard: {
          accountName: '',
          bankName: '',
          accountNo: ''
        },
        postWage: '0',
        salaryBank: null
      },
      // 员工基本信息item
      formBasicInfoItem: [
        { type: 'input', label: '姓名', placeholder: '请输入姓名', prop: 'name', model: 'name', style: 'ivu-col-span-6', fn: 'inputOnBlur' },
        { type: 'input', label: '英文名', placeholder: '请输入英文名', prop: 'eName', model: 'eName', style: 'ivu-col-span-6' },
        { type: 'select', label: '证件类型', placeholder: '请选择证件类型', prop: 'idType', model: 'idType', style: 'ivu-col-span-6', options: 'idcardtype', fn: 'idTypeChange' },
        { type: 'input', label: '身份证号码', placeholder: '请输入身份证号码', prop: 'idCardNo', model: 'idCardNo', style: 'ivu-col-span-6', fn: 'inputOnBlur' },
        { type: 'input', label: '证件号码', placeholder: '请输入证件号码', prop: 'otherIdCardNo', model: 'otherIdCardNo', style: 'ivu-col-span-6 display-none' },
        { type: 'datePicker', label: '出生日期', placeholder: '请选择出生日期', prop: 'birthDay', model: 'birthDay', style: 'ivu-col-span-6' },
        { type: 'select', label: '性别', placeholder: '请选择性别', prop: 'sex', model: 'sex', style: 'ivu-col-span-6', options: 'sex' },
        { type: 'input', label: '年龄', placeholder: '请输入年龄', prop: 'age', model: 'age', style: 'ivu-col-span-6' },
        { type: 'input', label: '民族', placeholder: '请输入民族', prop: 'race', model: 'race', style: 'ivu-col-span-6' },
        { type: 'input', label: '籍贯', placeholder: '请输入籍贯', prop: 'birthplace', model: 'birthplace', style: 'ivu-col-span-6' },
        { type: 'datePicker', label: '证件开始时间', placeholder: '开始时间', prop: 'idCardStartTime', model: 'idCardStartTime', style: 'ivu-col-span-6' },
        { type: 'datePicker', label: '证件到期时间', placeholder: '到期时间', prop: 'idCardEndTime', model: 'idCardEndTime', style: 'ivu-col-span-6' },
        { type: 'input', label: '身份证地址', placeholder: '请输入身份证地址', prop: 'idCardAddress', model: 'idCardAddress', style: 'ivu-col-span-6' },
        { type: 'input', label: '现居住地址', placeholder: '请输入现居住地址', prop: 'residentAddress', model: 'residentAddress', style: 'ivu-col-span-6' },
        { type: 'input', label: '手机号码', placeholder: '请输入手机号码', prop: 'phone', model: 'phone', style: 'ivu-col-span-6' },
        { type: 'input', label: 'Email', placeholder: '请输入Email', prop: 'email', model: 'email', style: 'ivu-col-span-6' },
        { type: 'input', label: '紧急联系人', placeholder: '请输入紧急联系人', prop: 'emergencyContact', model: 'emergencyContact', style: 'ivu-col-span-6' },
        { type: 'input', label: '紧急联系人电话', placeholder: '请输入紧急联系人电话', prop: 'emergencyContactPhone', model: 'emergencyContactPhone', style: 'ivu-col-span-6' },
        { type: 'select', label: '婚姻情况', placeholder: '请输入婚姻情况', prop: 'maritalStatus', model: 'maritalStatus', style: 'ivu-col-span-6', options: 'maritalstatus' },
        { type: 'select', label: '子女情况', placeholder: '请输入子女情况', prop: 'hasChildren', model: 'hasChildren', style: 'ivu-col-span-6', options: 'hasChildrenOps' },
        { type: 'input', label: '技术职称', placeholder: '请输入技术职称', prop: 'professionalTitle', model: 'professionalTitle', style: 'ivu-col-span-6' },
        { type: 'select', label: '最高学历', placeholder: '请输入最高学历', prop: 'degree', model: 'degree', style: 'ivu-col-span-6', options: 'degree' },
        { type: 'input', label: '毕业学校', placeholder: '请输入毕业学校', prop: 'schoolName', model: 'schoolName', style: 'ivu-col-span-6' },
        { type: 'datePicker', label: '毕业时间', placeholder: '毕业时间', prop: 'graduationDate', model: 'graduationDate', style: 'ivu-col-span-6' },
        { type: 'input', label: '专业', placeholder: '请输入专业', prop: 'discipline', model: 'discipline', style: 'ivu-col-span-6' },
        { type: 'datePicker', label: '入职时间', placeholder: '入职时间', prop: 'onBoardingDate', model: 'onBoardingDate', style: 'ivu-col-span-6' },
        { type: 'input', label: '所属公司', placeholder: '请输入所属公司', prop: 'companyName', model: 'companyName', style: 'ivu-col-span-6', isDisabled: true },
        { type: 'input', label: '部门', placeholder: '请输入部门', prop: 'department', model: 'department', style: 'ivu-col-span-6' },
        { type: 'input', label: '职业', placeholder: '请输入职业', prop: 'duty', model: 'duty', style: 'ivu-col-span-6' },
        { type: 'input', label: '工号', placeholder: '请输入工号', prop: 'employeeNo', model: 'employeeNo', style: 'ivu-col-span-6' },
        { type: 'select', label: '用工形式', placeholder: '请输入用工形式', prop: 'employeeType', model: 'employeeType', style: 'ivu-col-span-6', options: 'EmploymentForm' },
        { type: 'select', label: '在职状态', placeholder: '请输入在职状态', prop: 'beHiringName', model: 'beHiringName', style: 'ivu-col-span-6', options: 'beHiringOps' },
        { type: 'cascader', label: '所在地区', placeholder: '请输入所在地区', prop: 'city', model: 'city', style: 'ivu-col-span-6', options: 'cityId' },
        { type: 'input', label: '工资卡名称', placeholder: '请输入工资卡名称', prop: 'accountName', model: 'accountName', parent: 'salaryCard', style: 'ivu-col-span-6', isDisabled: true },
        { type: 'input', label: '工资卡开户行', placeholder: '请输入工资卡开户行', prop: 'bankName', model: 'bankName', parent: 'salaryCard', style: 'ivu-col-span-6' },
        { type: 'input', label: '工资卡卡号', placeholder: '请输入工资卡卡号', prop: 'accountNo', model: 'accountNo', parent: 'salaryCard', style: 'ivu-col-span-6' },
        { type: 'input', label: '岗位工资', placeholder: '请输入岗位工资', prop: 'postWage', model: 'postWage', style: 'ivu-col-span-6' },
        { type: 'select', label: '工资发放银行', placeholder: '请选择工资发放银行', prop: 'salaryBank', model: 'salaryBank', style: 'ivu-col-span-6', options: 'bankList' },
      ],

      rules: {
        name: [
          { required: true, message: '请输入姓名' }
        ],
        idType: [
          { required: true, message: '请选择证件类型' }
        ],
        idCardNo: [
          { required: true, type: 'string', validator: Common.validateIdCardNo }
        ],
        otherIdCardNo: [
          { required: true, type: 'string', message: '请输入证件号码' }
        ],
        birthDay: [
          { required: true, message: '请选择出生日期' }
        ],
        sex: [
          { required: true, message: '请选择性别' }
        ],
        age: [
          { required: true, message: '请输入年龄' },
          { type: 'string', message: '请输入正确的年龄', pattern: /^\d{2}$/ }
        ],
        onBoardingDate: [
          { required: true, message: '请选择入职时间' }
        ],
        // idCardEndTime: [
        //   { required: true, message: '请选择证件到期时间' }
        // ],
        // residentAddress: [
        //   { required: true, message: '请输入现居住地址' }
        // ],
        phone: [
          { required: true, message: '请输入手机号码' },
          // { type: 'string', message: '请输入正确的号码', pattern: /^((0\d{2,3}-\d{7,8})|(1[35847]\d{9}))$/ }
          { type: 'string', message: '请输入11位数的手机号码', pattern: /^\d{11}$/ }
        ],
        duty: [
          { required: true, message: '请输入职业' }
        ],
        employeeType: [
          { required: true, message: '请输入用工形式' }
        ],
        // bankName: [
        //   { required: true, message: '请输入工资卡开户行' }
        // ],
        // accountNo: [
        //   { required: true, message: '请输入工资卡卡号' },
        //   { type: 'string', message: '请输入正确的工资卡卡号', pattern: /^\d{12}/ }
        // ]
      },
      // rulesReplenish: {
      //   bankName: [
      //     { required: true, message: '请输入工资卡开户行' }
      //   ],
      //   accountNo: [
      //     { required: true, message: '请输入工资卡卡号' },
      //     { type: 'string', message: '请输入正确的工资卡卡号', pattern: /^\d{12}/ }
      //   ]
      // },
      arrListDown: {
        cityId: [],
        booleanJudge: [{ value: 'true', label: '是' }, { value: 'false', label: '否' }],
        tempOptions: [{ value: 0, label: '选项1' }, { value: 1, label: '选项2' }],
        hasChildrenOps: [{ value: 'true', label: '有' }, { value: 'false', label: '无' }],
        beHiringOps: [{ value: '在职', label: '在职' }, { value: '离职', label: '离职' }, { value: '离职未报停', label: '离职未报停', isDisabled: true }],
        idcardtype: [],
        sex: [],
        maritalstatus: [],
        degree: [],
        EmploymentForm: [],
        bankList: [],
      },
      isNext: false,
      currentCustomerManage: {},
      areaTree: [], // 中国所有城市树
      isFromRoster: null
    }
  },

  mounted () {
    this.getEnum()
    this.queryEmployeeType()
    this.queryBankList()
    this.formBasicInfo.Id = this.$route.query.employeeId // 员工ID
    this.formBasicInfo.companyId = this.$route.query.companyId // 公司ID
    this.formBasicInfo.companyName = this.$route.query.companyName // 公司名称
    this.isFromRoster = this.$route.query.isFromRoster // 是否从员工管理页面过来
    this.isToBeStaff = this.$route.query.isToBeStaff // 是否从待入职员工管理页面过来
    

    // this.arrListDown.cityId = JSON.parse(localStorage.getItem('provinceList')) // 全国省份列表
    // this.areaTree = JSON.parse(localStorage.getItem('areaTree')) // 获取中国所有城市树

    // URL参数有员工ID时，获取员工基本信息
    if (this.formBasicInfo.Id !== '' && this.formBasicInfo.Id !== undefined) {
      this.query()
    }

    if (this.$route.query.isCreateNew) { // isCreateNew参数为true时，为新增
      this.isOnlyView = false
    }
    // this.isNext = !this.$route.query.isCreateNew || this.$route.query.employeeId
    this.isNext = false // 每次都需要保存后才能下一步

    this.currentCustomerManage = JSON.parse(localStorage.getItem('currentCustomerManage')) // 缓存里的公司部分信息
    if (this.currentCustomerManage.typeValue !== 1) {
      console.log('❤ 银行信息、手机号码 必填')
      // this.rules = {...this.rules, ...this.rulesReplenish}
      // this.formBasicInfoItem.map(item => {
      //   if (['bankName', 'accountNo'].indexOf(item.model) !== -1) {
      //     item.style = item.style.concat(' is-required')
      //   }
      // })
    } else {
      console.log('☆ 人事代理公司，银行信息、手机号码 非必填')
      this.formBasicInfoItem.map(item => {
        if (['bankName', 'accountNo', 'phone'].indexOf(item.model) !== -1) {
          item.style = item.style.concat(' remove-required')
        }
      })
      delete this.rules.bankName
      delete this.rules.accountNo
      delete this.rules.phone
    }

    // this.getResignInfoList()
    // 不是新增时，获取员工离职表信息
    if (!this.$route.query.isCreateNew) {
      this.getResignInfoList()
    }
    this.getProvince()
  },

  methods: {
    /**
     * 查询所有省
     */
    getProvince () {
      dataApi.getProvince().then(res => {
        this.areaTree = res.data.data.map(item => {
          return {
            ...item,
            label: item.name,
            value: item.id,
            children: [],
            loading: false
          }
        })
      })
    },
    /**
     * 分级查询地区
     */
    loadDataCity (val, callback) {
      val.loading = true
      if (val.levelID === 2) {
        dataApi.getCity({ parentId: val.value }).then(res => {
          val.children = res.data.data.map(item => {
            return {
              ...item,
              label: item.name,
              value: item.id,
              children: [],
              loading: false
            }
          })
          val.loading = false
          callback()
        })
      } else {
        dataApi.getArea({ parentId: val.value }).then(res => {
          val.children = res.data.data.map(item => {
            return { ...item, label: item.name, value: item.id }
          })
          val.loading = false
          callback()
        })
      }
    },

    // 监听所有调用的方法
    listenCall (methodsWords, ...values) {
      this[methodsWords](...values)
    },

    // 数据字典
    getEnum () {
      let groupName = 'employee.idcardtype,employee.sex,employee.maritalstatus,employee.degree'
      Common.getEnum(groupName, this.arrListDown)
      let typeName = 'EmploymentForm'
      Common.getSelectValueList(typeName, this.arrListDown)
    },

    // 输入框失去焦点时触发
    inputOnBlur (index, model, value) {
      if (this.formBasicInfoItem[index].model === 'name') {
        this.formBasicInfo.accountName = this.formBasicInfo[this.formBasicInfoItem[index].model]
      }
      if (this.formBasicInfoItem[index].model === 'idCardNo') {
        var value = this.formBasicInfo[this.formBasicInfoItem[index].model]
        // 输入数值时，通过身份证号码计算年龄及性别
        // if (!isNaN(value)) {
        //   console.log('22222222')
        //   if (value.length === 15) {
        //     console.log('输入的是15位身份证号码')
        //     Common.getAge(value, 15, this.formBasicInfo)
        //   } else if (value.length === 18) {
        //     console.log('输入的是18位身份证号码')
        //     Common.getAge(value, 18, this.formBasicInfo)
        //   }
        // }
        if (+this.formBasicInfo.idType === 0) { // 证件类型为身份证时，通过身份证号码计算年龄及性别
          if (value.length === 15) {
            Common.getAge(value, 15, this.formBasicInfo)
          } else if (value.length === 18) {
            Common.getAge(value, 18, this.formBasicInfo)
          }
        }
      }
    },

    // 表单提交
    handleSubmit (name) {
      if(!this.isToBeStaff){
        this.formBasicInfo.id = this.insuranceId
      }
      // 表单二级obj解析
      this.formBasicInfoItem.map(item => {
        if (item.parent) { // 查找表单里面是否有二级obj
          this.formBasicInfo.salaryCard[item.model] = this.formBasicInfo[item.model] // 如果有二级obj，则把表单里相应的字段放在二级obj里
          // delete this.formBasicInfo[item.model] // 然后删除表单原来的字段
        }
      })

      // 用工形式解析
      this.arrListDown.EmploymentForm.map(item => {
        if (item.value === this.formBasicInfo.employeeType) {
          this.formBasicInfo.employeeTypeName = item.label
        }
      })

      // 证件类型解析
      if (+this.formBasicInfo.idType !== 0) {
        this.formBasicInfo.idCardNo = this.formBasicInfo.otherIdCardNo
      } else {
        this.formBasicInfo.otherIdCardNo = this.formBasicInfo.idCardNo
      }
      // console.log('在职状态beHiring1: ', this.formBasicInfo.beHiring)
      // var beHiring = this.formBasicInfo.beHiring === '在职' ? 'true' : 'false'
      // console.log('beHiring: ', beHiring)
      // this.formBasicInfo.beHiring = beHiring
      // console.log('在职状态beHiring2: ', this.formBasicInfo.beHiring)
      // console.log('保存基本信息params: ', this.formBasicInfo)
      delete this.formBasicInfo.beHiring
      this.formBasicInfo.beHiring = this.formBasicInfo.beHiringName == '在职' ? 'true' : 'false'
      console.log('❤ this.formBasicInfo.beHiring： ', this.formBasicInfo.beHiring)

      this.$refs.formBasicInfo.validate((valid) => {
        if (valid) {
          console.log('提交表单', this.formBasicInfo,this.isToBeStaff)
          if(this.isToBeStaff){
            EmployeeQuickEntryApi.save(this.formBasicInfo).then(resp => {
              console.log(resp,'resp')
              if (resp.success === true||resp.data.success === true) {
                this.$Message.success(resp.data.message)
                this.insuranceId = resp.data.data // 保存成功后返回保险ID
                this.isNext = true
                this.$emit('saveSuccess', resp.data.data, this.$route.query.isCreateNew)
                // this.query()
                if (!this.$route.query.isCreateNew) { // 非新建情况下，保存基本信息成功后，手动获取员工基本信息
                  this.query()
                }
              } else {
                this.$Message.error({
                  content: resp.data.message,
                  duration: 10,
                  closable: true
                })
              }
            })
          } else {
            EmployeesApi.postEmployee(this.formBasicInfo).then(resp => {
              console.log(resp,'resp')
              if (resp.status === true||resp.data.success === true) {
                this.$Message.success(resp.data.message)
                this.insuranceId = resp.data.data // 保存成功后返回保险ID
                this.isNext = true
                this.$emit('saveSuccess', resp.data.data, this.$route.query.isCreateNew)
                // this.query()
                if (!this.$route.query.isCreateNew) { // 非新建情况下，保存基本信息成功后，手动获取员工基本信息
                  this.query()
                }
              } else {
                this.$Message.error({
                  content: resp.message,
                  duration: 10,
                  closable: true
                })
              }
            })
          }
        }
      })
    },

    // 上一步
    handlepageUp () {
      Common.pageUp(this)
    },

    // 下一步
    handlepageDown () {
      Common.pageDown(this)
    },

    // 获取单个员工基本信息
    async query () {
      var self = this
      var params = {
        id: this.formBasicInfo.Id
      }
      let res = this.isToBeStaff?await EmployeeQuickEntryApi.getModel(params.id):await EmployeesApi.getEmployee(params)
      // if (res.data.code === 200 && res.data.success) {
      if (true) {
        var tempBasicInfo = {
          idCardNo: res.data.data.idCardNo,
          idType: res.data.data.idType
        }
        // 将身份证信息放入缓存，调取社保/公积金/商保记录时使用
        localStorage.setItem('employeeBasicInfo', JSON.stringify(tempBasicInfo))

        if (res.data.data.serverFee) {
          this.$emit('basicInfoServerFee', res.data.data.serverFee)
        } else {
          this.$emit('basicInfoServerFee', 0)
        }
        
        var result = res.data.data
        
        // 根据获取到的数据字段循环结果并赋值到表单
        for (var item in result) {
          if (typeof result[item] === 'boolean') {
            this.formBasicInfo[item] = result[item] + ''
          } else if (typeof result[item] === 'object') {
            for (var c_item in result[item]) {
              this.formBasicInfo[c_item] = result[item][c_item] ? result[item][c_item] + '' : ''
            }
          } else {
            if (item === 'city') {
              var tempCity = result[item].substring(1, result[item].length - 1)
              this.formBasicInfo[item] = tempCity.split(',')
            } else {
              this.formBasicInfo[item] = result[item] + ''
            }
          }
          if (item === 'beHiring') {
            this.formBasicInfo.beHiringName = result[item]
          }
        }
        if (this.isToBeStaff) {
          this.formBasicInfo.IDCardFrontAttachmentId = res.data.idCardFront.attachmentId
          this.formBasicInfo.IDCardBackAttachmentId = res.data.idCardBack.attachmentId
          console.log(res,'哈哈哈哈哈',this.formBasicInfo)
        }
        // Object.keys(result).forEach(item => {
        //   if (typeof result[item] == 'boolean') {
        //     this.formBasicInfo[item] = result[item] + ''
        //   } else if (typeof result[item] == 'object') {
        //     Object.keys(result[item]).forEach(c_item => {
        //       this.formBasicInfo[c_item] = result[item][c_item] + ''
        //     })
        //   } else {
        //     this.formBasicInfo[item] = result[item] + ''
        //   }
        // })

        this.judgeIdType(+this.formBasicInfo.idType)

        if (result.insuranceInfos) {
          var serviceFeeType = result.insuranceInfos.serviceFeeType
          this.$emit('querySuccess', serviceFeeType)
        }
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
        this.$router.back(-1)
      }
    },

    // 修改
    handleModify () {
      this.isNext = true
      // this.$emit('handleModify', 0)
      this.isOnlyView = false
    },

    // 时间控件
    handleChangeDatePicker (model, value) {
      this.formBasicInfo[model] = value
    },

    // 证件类型改变
    idTypeChange (value) {
      this.formBasicInfo.idCardNo = ''
      this.judgeIdType(value)
    },

    // 证件公用
    judgeIdType (value) {
      if (+value === 0) {
        this.formBasicInfoItem.map(item => {
          if (item.model === 'idCardNo') {
            item.style = 'ivu-col-span-6'
          }
          if (item.model === 'otherIdCardNo') {
            item.style = 'ivu-col-span-6 display-none'
          }
        })
      } else {
        this.formBasicInfo.otherIdCardNo = this.formBasicInfo.idCardNo
        this.formBasicInfoItem.map(item => {
          if (item.model === 'idCardNo') {
            item.style = 'ivu-col-span-6 display-none'
          }
          if (item.model === 'otherIdCardNo') {
            item.style = 'ivu-col-span-6'
            if (value == 1) {
              item.label = '港澳居民通行证'
            } else if (value == 2) {
              item.label = '台湾居民通行证'
            } else if (value == 4) {
              item.label = '护照号码'
            }
          }
        })
      }
    },

    // 添加离职信息 - 显示弹窗
    handleShowCreateDepartureInfoModal (id) {
      this.$refs.CreateDepartureInfoModal.show()
    },

    /**
     * 离职信息列表 分页查询接口
     * @param {Object} obj {pageIndex, pageSize}
     */
    async getResignInfoList () {
      var params = {
        id: this.$route.query.employeeId
      }

      let res = await EmployeesApi.getResignInfoList(params)
      if (res.data.code === 200 && res.data.success) {
        var result = res.data.data
        this.tableData = [result]
        Object.keys(this.$refs.CreateDepartureInfoModal.formData).forEach(key => {
          this.$refs.CreateDepartureInfoModal.formData[key] = result[key] + ''
        })

        // 经济补偿金为false时，后面两个框隐藏
        if (!result.haveCompensation) {
          this.$refs.CreateDepartureInfoModal.formItem.map(item => {
            if (item.prop === 'amount' || item.prop1 === 'periodFrom') {
              item.isShow = false
            }
          })
        }
      } else {
        this.tableData = []
      }
    },

    // 所在地区选择
    areaTreeChange (model, value) {
      this.formBasicInfo[model] = value
    },

    // 获取默认用工形式
    async queryEmployeeType () {
      var params = {
        TypeName: '用工形式',
        Enabled: true
      }
      let res = await SysBasedataApi.getList(params)
      if (res.status === 200 && res.data.success) {
        res.data.data.map(item => {
          if (item.isDefault) {
            this.formBasicInfo.employeeType = item.value
          }
        })
      }
    },

    // 返回员工花名册列表
    goEmployeeBookList () {
      EBbase.goEmployeeBookList(this.$router, this.formBasicInfo.companyId, this.formBasicInfo.companyName)
    },

    // 返回员工管理
    goRoster () {
      if(this.isToBeStaff){
        this.$router.back(-1)
      }else{
        EBbase.goRoster(this.$router)
      }
    },

    // 获取银行下拉
    async queryBankList () {
      var params = {
        HasPaging: true,
        PageIndex: 1,
        PageSize: 100
      }
      let res = await OrganizationBankApi.getList(params)
      console.log('获取银行下拉res: ', res)
      if (res.status === 200 && res.data.success) {
        this.arrListDown.bankList = res.data.data.map(item => {return {label: item.bankName, value: item.bankName}})
      } else {
        this.arrListDown.bankList = []
      }
      this.loading = false
    },
  }
}
</script>

<style lang="less" scope>
</style>
